<head>
<style>
<?php
	include "../css/css.php";
?>
</style>
</head>
<?php
	include "../db.php";
	session_start();
	if(isset($_GET['username']))
		$username = $_GET['username'];
	if(isset($_SESSION['username']))
		$session_username = $_SESSION['username'];
	if($username == $session_username)
	{
		$category = $_SESSION['category'];
		$query_category = "select * from $category where username = '$username'";
		$result_category = mysql_query($query_category);
		if($result_category)
		{
			$rows_category = mysql_fetch_assoc($result_category);
			$id = $rows_category['id'];
			$name = $rows_category['username'];
		}
		else
		{
			header("location:../login/login.php?msg=don't do it next time1!!!");
		}
	}
	else
	{
		header("location:../login/login.php?msg=don't do it next time2!!!");
	}

	/*echo "<a href = '../logout.php'>logout</a><br />";
	echo "<a href = 'profile_view.php?username=$username'>profile</a><br />";
	echo "<a href = 'profile_update.php?username=$username'>update profile</a><br />";*/

?>
<body>
<div class='divCell_input' style='width:15%;height:100%'>
	<div class='divCell_input' style='width:100%;height:15%'> 
		<img alt='Profile Picture'></img>
	</div>
	<div class='divCell_input' style='width:100%;height:84%'> 
	<?php 
			include "../left_bottom_navigation.php";
	?>
	</div>
</div>
<div class='divCell_input' style='width:84%;height:15%'>
	
</div>
<div class='divCell_input' style='width:84%;height:84%'>
	<font color='blue'> <b>FR Module</b> </font>
	<div style = 'height:80px;width:200px;border:1px solid;'>
	<form action = 'friend_request_handler.php' method = 'post'>
		<input type = 'text' name = 'friend_username' placeholder='Friend Name'/>
		<input type = 'submit' value = 'Send Request' />
	</form>
</div> 
<div style = 'height:200px;width:600px;border:1px solid;'>
<?
	$query_send = "select * from friend where friend1_username = '$username'";
	$result_send = mysql_query($query_send);
		echo "<h3>Status of sent FR</h3>";
	for($i = 0; $i < mysql_num_rows($result_send); $i++)
	{
		$rows_send = mysql_fetch_assoc($result_send);
		$status = $rows_send['confirm'];
		$friend2 = $rows_send['friend2_username'];
		if($status == 0)
		{
			echo "<a href = 'profile_view.php?username=$friend2'>$friend2</a>&nbsp;&nbsp;&nbsp;<a href = 'friend_request_cancel.php?friend1=$username&friend2=$friend2'>cancel</a><br />";
		}
		if($status == 1)
		{
			echo "<a href = 'profile_view.php?username=$friend2'>$friend2</a>&nbsp;&nbsp;&nbsp;accepted<br />";
		}
	}
?>
</div>
<div style = 'height:200px;width:600px;border:1px solid;'>
<?
	$query_receive = "select * from friend where friend2_username = '$username'";
	$result_receive = mysql_query($query_receive);
		echo "<h3>Status of Received FR</h3>";
	for($i = 0; $i < mysql_num_rows($result_receive); $i++)
	{
		$rows_receive = mysql_fetch_assoc($result_receive);
		$status = $rows_receive['confirm'];
		$friend1 = $rows_receive['friend1_username'];
		if($status == 0)
		{
			echo "<a href = 'profile_view.php?username=$friend1'>$friend1</a>&nbsp;&nbsp;&nbsp;<a href = 'friend_request_accept.php?friend1=$friend1&friend2=$username'>accept</a><br />";
		}
		if($status == 1)
		{
			echo "<a href = 'profile_view.php?username=$friend1'>$friend1</a>&nbsp;&nbsp;&nbsp;accepted<br />";
		}
	}
?>
</div>
<?

	if(isset($_GET['msg']))
	{
		$msg = $_GET['msg'];
	}
	else
	{
		$msg = "";
	}
	echo $msg;
?>
</div>
</div>
</body>


